//
//  Tools.m
//  MagicBox
//
//  Created by dllo on 16/8/9.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "Tools.h"

@implementation Tools

+ (NSDate *)returnDate:(NSString *)string{
    NSDateFormatter *fomatter = [[NSDateFormatter alloc] init];
    [fomatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    return [fomatter dateFromString:string];
}


+ (NSString *)returnString:(NSDate *)date{
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //    [dateFormatter setDateFormat:@"MM-dd HH:mm"];
    //    dateFormatter.dateFormat = @"MM-dd-yyyy";
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    return [dateFormatter stringFromDate:date];
}



+ (CGFloat)getTextHeight:(NSString *)text withWidth:(CGFloat)width withFontSize:(NSInteger)size{
    NSDictionary *dic = @{
                          NSFontAttributeName : [UIFont systemFontOfSize:size]
                          };
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake(width, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return rect.size.height;
    
}


+ (CGFloat)getTextWidth:(NSString *)text withFontSize:(NSInteger)size{
    NSDictionary *dic = @{
                          NSFontAttributeName : [UIFont systemFontOfSize:size]
                          };
    CGRect rect = [text boundingRectWithSize:CGSizeMake(1000, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic                                  context:nil];
    return rect.size.width;
    
}

+ (CGFloat)getImageHeight:(NSString *)imageName withWidth:(CGFloat)width{
    NSURL *imageURL = [NSURL URLWithString:imageName];
    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
    CGFloat imageHeight = image.size.height / image.size.width * width;
    return imageHeight;
}








@end
